//	--------------------------------------------------------------------
//	Copyright(C) 2006,2007 Zhao Yukun. All rights reserved.
//	This file is a part of the Xeres system.
//	Xeres 2007
//	Contact : xeres.engine@gmail.com
//	$(reservedInfo)
//	$(reservedDeclaration)
//	--------------------------------------------------------------------
///	@file	<XSpace.h>
///	@path	~/src/scene/xworld/
///	@date	2007/12/19
///	@desc	Middle level of world structure.

#pragma once

#include "xeres.h"

#include "scene/ScenePresentation.h"
#include "scene/xworld/XWorld.h"

namespace xeres {

	/*!
		\class	XSpace
		\brief
	*/
	class XSpace : public IObject
	{
	public:

		/// \ctor
		XSpace( void );

		/// \dtor
		virtual ~XSpace( void );

		DECL_IOBJECT_CLASS( XSpace , IObject );

	//@ interface

		/*!
			\brief		Update space elements.
		*/
		virtual void Tick( const Frame& frame );

		/*!
			\brief		Update scene presentations.
		*/
		virtual void Present( ScenePresentation& sp );

		/*!
			\brief		Get axis aligned bounding box.
		*/
		virtual const Box<float>& GetBound( void );


	//@ local

	private:

		// chunk note
		struct _ChunkNote
		{
			// chunk color
			uint			m_color;

			// chunk coordinates in space
			int				m_x , m_y;

			Ref<XChunk>		m_chunk;
		};

	//@ data

		// space size
		int							m_gridWidth;
		int							m_gridHeight;
		// fixed region [ -w/2 , -h/2 , w/2 , h/2 ]
		Rect<int>					m_spaceRegion;

		// current central chunk
		RefWeak< XChunk >		m_central;

		// space name
		WString						m_spaceName;

		// chunks in space
		std::vector< _ChunkNote >	m_chunks;

		// borders that may connect to other spaces
		std::deque< Ref<XBorder> >	m_borders;

		// chunks that is about to leave space
		// at every synchronized, this queue will be flushed
		std::deque< Ref<XChunk> >	m_leaving;

	};

} // namespace xeres
